<template>
  <div>


    <el-button type="text" @click="addDialogFormVisible = true">新增</el-button>
    <el-button type="text" @click="deleteAssign">删除</el-button>
    <el-table
      highlight-current-row
      :data="tableData"
      @current-change="handleCurrentChange"
      style="width: 100%">
      <el-table-column
        prop="ynName"
        label="名称">
      </el-table-column>
    </el-table>

    <el-dialog title="" :visible.sync="addDialogFormVisible">
      <el-form label-width="10%" :model="form">
        <el-form-item label="名称">
          <el-input v-model="form.ynName" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="addDialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="saveOrUpdate">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "ynDepartment",
  created() {
    this.getynDepartment()
    this.fetchRadioOptions()
  },
  methods: {
    getynDepartment: function () {
      this.axios.post('/ynDepartment/list').then(res => {
        if (!!res.data.data) {
          this.tableData = res.data.data;
        }
      })
    },
    saveOrUpdate() {
      this.axios.post('/ynDepartment/saveOrUpdate', this.form).then(res => {
        if (200 === res.data.code) {
          this.addDialogFormVisible = false;
          this.getynDepartment();
        }
      })
    },
    update() {
      this.addDialogFormVisible = true;
    },
    deleteAssign() {
      this.axios.post('/ynDepartment/delete', this.currentRow).then(res => {
        if (200 === res.data.code) {
          this.getynDepartment();
        }
      })
    },
    fetchRadioOptions() {
      // 假设 getRadioData 是一个返回 Promise 的函数，用来获取接口数据
      this.axios.post('/ynDepartment/list').then(response => {
        this.radioOptions = response.data.data; // 假设响应格式为 { data: [] }
      });
    },
    handleCurrentChange(val) {
      this.currentRow = val;
    }
  },
  data() {
    return {
      tableData: [],
      currentRow: null,
      form: {
        ynName: '',
        ynDepartment: '',
        ynDepartmentName: '',
      },
      addDialogFormVisible: false,
      radioValue: '', // 选中的单选按钮的值
      radioOptions: [] // 存储从接口获取的数据
    }
  }
}
</script>

<style scoped>

</style>
